function residual = static_resid(T, y, x, params, T_flag)
% function residual = static_resid(T, y, x, params, T_flag)
%
% File created by Dynare Preprocessor from .mod file
%
% Inputs:
%   T         [#temp variables by 1]  double   vector of temporary terms to be filled by function
%   y         [M_.endo_nbr by 1]      double   vector of endogenous variables in declaration order
%   x         [M_.exo_nbr by 1]       double   vector of exogenous variables in declaration order
%   params    [M_.param_nbr by 1]     double   vector of parameter values in declaration order
%                                              to evaluate the model
%   T_flag    boolean                 boolean  flag saying whether or not to calculate temporary terms
%
% Output:
%   residual
%

if T_flag
    T = modelG.static_resid_tt(T, y, x, params);
end
residual = zeros(20, 1);
lhs = params(1)*y(6);
rhs = params(4)*(1-params(3))*y(4)+y(10)*params(3)*T(1)*(-params(13))*(1-T(1))+(params(1)-params(4)*(1-params(3)))*y(15);
residual(1) = lhs - rhs;
lhs = (1-params(1))*y(7);
rhs = (1-params(3))*(1-params(4))*y(5)+y(10)*T(1)*params(3)*params(13)*(1-T(1))+y(15)*params(3)*(1-T(1));
residual(2) = lhs - rhs;
lhs = params(11)*y(8);
rhs = y(8)*params(11)*params(9)+(1-params(11))*(1-params(11)*params(9))*(y(15)*params(7)+y(6)*params(8)-y(10)*(1-T(1)));
residual(3) = lhs - rhs;
lhs = params(12)*y(9);
rhs = y(9)*params(9)*params(12)+(1-params(12))*(1-params(9)*params(12))*(y(15)*params(7)+y(7)*params(8)+T(1)*y(10));
residual(4) = lhs - rhs;
residual(5) = params(10)*y(20)-params(14)*y(14);
lhs = y(15)*params(7);
rhs = y(15)*params(7)-(y(14)-y(20));
residual(6) = lhs - rhs;
lhs = y(20);
rhs = T(1)*y(8)+(1-T(1))*y(9);
residual(7) = lhs - rhs;
lhs = y(13);
rhs = params(1)*y(8)+(1-params(1))*y(9);
residual(8) = lhs - rhs;
lhs = y(11);
rhs = params(1)*y(6)+(1-params(1))*y(7);
residual(9) = lhs - rhs;
lhs = y(12);
rhs = params(4)*y(4)+(1-params(4))*y(5);
residual(10) = lhs - rhs;
lhs = y(10);
rhs = y(10)+y(8)-y(9);
residual(11) = lhs - rhs;
lhs = y(2);
rhs = y(2)*params(5)+params(15)*x(1);
residual(12) = lhs - rhs;
lhs = y(3);
rhs = y(3)*params(6)+params(16)*x(2);
residual(13) = lhs - rhs;
lhs = y(4);
rhs = y(2)*0.16;
residual(14) = lhs - rhs;
lhs = y(5);
rhs = y(3)*0.16;
residual(15) = lhs - rhs;
lhs = y(1);
rhs = y(2)+y(3);
residual(16) = lhs - rhs;
residual(17) = y(9);
residual(18) = y(8);
residual(19) = y(20);
lhs = y(19);
rhs = y(12)*params(2);
residual(20) = lhs - rhs;
if ~isreal(residual)
  residual = real(residual)+imag(residual).^2;
end
end
